package com.yan.demo;

import java.io.*;

/**
 * @author taoge
 * @Date 2024/8/6 10:52
 * @Description
 */
public class Demo1 {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("D:\\IdeaProject\\javaSE-Plus\\day12_code\\src\\com\\yan\\demo\\User.txt");
        write(fos);
        FileInputStream fis = new FileInputStream("D:\\IdeaProject\\javaSE-Plus\\day12_code\\src\\com\\yan\\demo\\User.txt");
        read(fis);
        readAndWrite(fos ,fis);
    }

    public static void read(FileInputStream fis) throws IOException {
        InputStreamReader isr = new InputStreamReader(fis , "GBK");
        char[] car = new char[1024];
        int len = -1;
        while((len = isr.read(car)) != -1){
            System.out.println(new String(car , 0 ,len));
        }

        //isr.close();

    }

    public static void write(FileOutputStream fos) throws IOException {
        OutputStreamWriter osw = new OutputStreamWriter(fos , "GBK");
        String[] car = {"java中,C++国"};
        for (String s : car) {
            osw.write(s);
            osw.flush();
        }
        //osw.close();
    }

    public static void readAndWrite(FileOutputStream fos , FileInputStream fis) throws IOException {
        OutputStreamWriter osw = new OutputStreamWriter(fos , "GBK");
        InputStreamReader isr = new InputStreamReader(fis , "GBK");
        osw.write("软帝");
        osw.flush();
        char[] car = new char[1024];
        int len = -1;
        while((len = isr.read(car)) != -1){
            System.out.println(new String(car , 0 ,len));

        }

        isr.close();
        osw.close();
    }
}
